package com.baijiayun.liveuibase.utils

import android.view.View
import android.view.ViewGroup
import com.baijiayun.livecore.context.LPConstants
import com.baijiayun.livecore.context.LiveRoom

/**
 * Created by pengwenjian on 2020/11/16
 * Describe:
 */

fun getParentViewGroup(view: View?): ViewGroup? {
    return if (view?.parent != null && view.parent is ViewGroup) view.parent as ViewGroup else null
}


/**
 * emoji表情替换
 *
 * @param source 原字符串
 * @param slipStr emoji表情替换成的字符串
 * @return 过滤后的字符串
 *
 * 对某些emoji字符无效
 */
fun filterEmoji(source: String, slipStr: String?): String? {
    return if (!source.isNullOrBlank()) {
        source.replace("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]".toRegex(), slipStr!!)
    } else {
        source
    }
}

fun isOnlyEmojis(source: String): Boolean {
    return filterEmoji(source, "").isNullOrEmpty()
}
/**
 * 积分tab规则
 * 1.分组课堂和线上双师，大班老师、助教显示tab
 * 2.分组课堂和线上双师，小班老师、助教不显示tab
 * 3.分组课堂和线上双师，学生在大班且能查看所有成员（配置项）显示tab
 * 4.小班课非自习室显示tab
 */
fun showBonusPointsTab(liveRoom: LiveRoom?): Boolean {
    if (liveRoom == null) {
        return false
    }
    if (liveRoom.roomType != LPConstants.LPRoomType.NewSmallGroup) {
        return if (liveRoom.isGroupClass || liveRoom.isNewGroupClass) {
            when {
                liveRoom.isTeacherOrAssistant -> {
                    true
                }
                liveRoom.isGroupTeacherOrAssistant -> {
                    false
                }
                else -> {
                    liveRoom.isParentRoom && !liveRoom.onlineUserVM.enableMyGroupUsersPublish()
                }
            }
        } else {
            false
        }
    } else {
        return !liveRoom.studyRoomVM.isStudyRoom
    }
}
